package com.hbpa.pan.server.modules.user.utils;

import com.hbpa.pan.core.constants.RPanConstants;

import java.util.Objects;

/**
 * @author: BlcakTiger
 * @date: 2023/10/23 19:58
 * @contact: hsf6661@163.com
 * @description: 用户id存储工具类
 */
public class UserIdUtil {

    private static ThreadLocal<Long> threadLocal = new ThreadLocal<>();

    /**
     * 设置当前线程的用户id
     * @param userId
     */
    public static void set(Long userId){
        threadLocal.set(userId);
    }

    /**
     * 获取当前线程用户id
     * @return
     */
    public static Long get(){
        long userId = threadLocal.get();
        if (Objects.isNull(userId)){
            return RPanConstants.ZERO_LONG;
        }
        return userId;
    }
}
